00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef PTI33_PARSER_HPP_
00014 #define PTI33_PARSER_HPP_
00015
00016 #define OLD_MAP
00017
00018 #include <boost/algorithm/string/split.hpp>
00019 #include <boost/algorithm/string/classification.hpp>
00020 #ifndef OLD_MAP
00021 #include <boost/unordered_map.hpp>
00022 #endif
00023 #include <vector>
00024 #include <map>
00025 #include <cstdio>
00026 #include <cstdlib>
00027
00028 #include "gridpack/utilities/exception.hpp"
00029 #include "gridpack/timer/coarse_timer.hpp"
00030 #include "gridpack/stream/input_stream.hpp"
00031 #include "gridpack/parser/dictionary.hpp"
00032 #include "gridpack/network/base_network.hpp"
00033 #include "gridpack/parser/base_parser.hpp"
00034 #include "gridpack/parser/base_pti_parser.hpp"
00035
00036 #define TERM_CHAR '0'
00037
00038
00039 namespace gridpack {
00040 namespace parser {
00041
00042
00043 template <class _network>
00044 class PTI33_parser : public BasePTIParser<_network>
00045 {
00046 public:
00047
00048
00049
00050
00051
00052
00053 PTI33_parser(boost::shared_ptr<_network> network)
00054 : p_network(network), p_maxBusIndex(-1)
00055 {
00056 this->setNetwork(network);
00057 p_network_data = network->getNetworkData();
00058 }
00059
00060
00061
00062
00063 virtual ~PTI33_parser()
00064 {
00065 p_busData.clear();
00066 p_branchData.clear();
00067 }
00068
00069
00070
00071
00072
00073 void parse(const std::string &fileName)
00074 {
00075 p_timer = gridpack::utility::CoarseTimer::instance();
00076 p_timer->configTimer(false);
00077 int t_total = p_timer->createCategory("Parser:Total Elapsed Time");
00078 p_timer->start(t_total);
00079 gridpack::utility::StringUtils util;
00080 std::string tmpstr = fileName;
00081 util.trim(tmpstr);
00082 std::string ext = this->getExtension(tmpstr);
00083 if (ext == "raw") {
00084 getCase(tmpstr);
00085
00086 this->createNetwork(p_busData,p_branchData);
00087 } else if (ext == "dyr") {
00088 this->getDS(tmpstr);
00089 }
00090 p_timer->stop(t_total);
00091 p_timer->configTimer(true);
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 void getImpedenceTable(int tableID, std::vector<double> &turns,
00101 std::vector<double> &scale)
00102 {
00103 turns.clear();
00104 scale.clear();
00105 if (p_imp_corr_table.find(tableID) != p_imp_corr_table.end()) {
00106 boost::shared_ptr<gridpack::component::DataCollection> data =
00107 p_imp_corr_table.find(tableID)->second;
00108 int i;
00109 char buf[32];
00110 for (i=0; i<11; i++) {
00111 sprintf(buf,"XFMR_CORR_TABLE_T%d",i+1);
00112 double tval, sval;
00113 bool ok = data->getValue(buf,&tval);
00114 sprintf(buf,"XFMR_CORR_TABLE_F%d",i+1);
00115 ok = ok && data->getValue(buf,&sval);
00116 if (ok) {
00117 turns.push_back(tval);
00118 scale.push_back(sval);
00119 } else {
00120 break;
00121 }
00122 }
00123 }
00124 }
00125
00126 protected:
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 void getCase(const std::string & fileName)
00138 {
00139 int t_case = p_timer->createCategory("Parser:getCase");
00140 p_timer->start(t_case);
00141 p_busData.clear();
00142 p_branchData.clear();
00143 p_busMap.clear();
00144
00145 MPI_Comm comm = static_cast<MPI_Comm>(p_network->communicator());
00146
00147 int me(p_network->communicator().rank());
00148
00149 if (me == 0) {
00150 p_istream.openFile(fileName.c_str());
00151 if (!p_istream.isOpen()) {
00152 char buf[512];
00153 sprintf(buf,"Failed to open network configuration file: %s\n\n",
00154 fileName.c_str());
00155 throw gridpack::Exception(buf);
00156 }
00157 find_case();
00158 } else {
00159 p_case_sbase = 0.0;
00160 p_case_id = 0;
00161 }
00162
00163
00164 double sval = p_case_sbase;
00165 double rval;
00166 int nprocs = p_network->communicator().size();
00167 int ierr = MPI_Allreduce(&sval,&rval,1,MPI_DOUBLE,MPI_SUM,comm);
00168 p_case_sbase = rval;
00169
00170 int isval, irval;
00171 isval = p_case_id;
00172 ierr = MPI_Allreduce(&isval,&irval,1,MPI_INT,MPI_SUM,comm);
00173 p_case_id = irval;
00174 this->setCaseID(p_case_id);
00175 this->setCaseSBase(p_case_sbase);
00176
00177 if (me == 0) {
00178 find_buses();
00179 find_loads();
00180 find_fixed_shunts();
00181 find_generators();
00182 find_branches();
00183 find_transformer();
00184 find_area();
00185 find_2term();
00186 find_vsc_line();
00187 find_imped_corr();
00188 find_multi_term();
00189 find_multi_section();
00190 find_zone();
00191 find_interarea();
00192 find_owner();
00193 find_facts();
00194 find_switched_shunt();
00195
00196 #if 0
00197
00198 int i;
00199 printf("BUS data size: %d\n",(int)p_busData.size());
00200 for (i=0; i<p_busData.size(); i++) {
00201 printf("Dumping bus: %d\n",i);
00202 p_busData[i]->dump();
00203 }
00204 printf("BRANCH data size: %d\n",(int)p_branchData.size());
00205 for (i=0; i<p_branchData.size(); i++) {
00206 printf("Dumping branch: %d\n",i);
00207 p_branchData[i]->dump();
00208 }
00209 #endif
00210 p_istream.close();
00211 }
00212
00213 int stables = 0;
00214 int ntables;
00215 if (me == 0) {
00216 stables = p_imp_corr_table.size();
00217 }
00218 ierr = MPI_Allreduce(&stables, &ntables, 1, MPI_INT, MPI_SUM, comm);
00219 #if 0
00220 if (ntables > 0) {
00221
00222 if (me == 0) {
00223 int idx;
00224 for (idx=1; idx<nprocs; idx++) {
00225 static_cast<boost::mpi::communicator>(
00226 p_network->communicator()).send(idx,idx,p_imp_corr_table);
00227 }
00228 } else {
00229 p_imp_corr_table.clear();
00230 static_cast<boost::mpi::communicator>(
00231 p_network->communicator()).recv(0,me,p_imp_corr_table);
00232 }
00233 }
00234 #endif
00235 p_network->broadcastNetworkData(0);
00236 p_network_data = p_network->getNetworkData();
00237 p_timer->stop(t_case);
00238 }
00239
00240 void find_case()
00241 {
00242 std::string line;
00243
00244 p_istream.nextLine(line);
00245 while (check_comment(line)) {
00246 p_istream.nextLine(line);
00247 }
00248 std::vector<std::string> split_line;
00249
00250 this->cleanComment(line);
00251 boost::algorithm::split(split_line, line, boost::algorithm::is_any_of(","),
00252 boost::token_compress_off);
00253
00254
00255 p_case_id = atoi(split_line[0].c_str());
00256
00257
00258 p_case_sbase = atof(split_line[1].c_str());
00259
00260 p_network_data->addValue(CASE_SBASE, p_case_sbase);
00261 p_network_data->addValue(CASE_ID, p_case_id);
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 }
00281
00282 void find_buses()
00283 {
00284 std::string line;
00285 int index = 0;
00286 int o_idx;
00287 p_istream.nextLine(line);
00288 p_istream.nextLine(line);
00289 p_istream.nextLine(line);
00290
00291 while(test_end(line)) {
00292 std::vector<std::string> split_line;
00293 this->cleanComment(line);
00294 boost::split(split_line, line, boost::algorithm::is_any_of(","),
00295 boost::token_compress_off);
00296 boost::shared_ptr<gridpack::component::DataCollection>
00297 data(new gridpack::component::DataCollection);
00298 int nstr = split_line.size();
00299
00300
00301 o_idx = atoi(split_line[0].c_str());
00302 if (p_maxBusIndex<o_idx) p_maxBusIndex = o_idx;
00303 data->addValue(BUS_NUMBER, o_idx);
00304 p_busData.push_back(data);
00305 p_busMap.insert(std::pair<int,int>(o_idx,index));
00306
00307
00308 data->addValue(CASE_SBASE, p_case_sbase);
00309 data->addValue(CASE_ID, p_case_id);
00310
00311
00312 std::string bus_name = split_line[1];
00313
00314
00315 storeBus(bus_name, o_idx);
00316 if (nstr > 1) data->addValue(BUS_NAME, bus_name.c_str());
00317
00318
00319 if (nstr > 2) data->addValue(BUS_BASEKV, atof(split_line[2].c_str()));
00320
00321
00322 if (nstr > 3) data->addValue(BUS_TYPE, atoi(split_line[3].c_str()));
00323
00324
00325 if (nstr > 4) data->addValue(BUS_AREA, atoi(split_line[4].c_str()));
00326
00327
00328 if (nstr > 5) data->addValue(BUS_ZONE, atoi(split_line[5].c_str()));
00329
00330
00331 if (nstr > 6) data->addValue(BUS_OWNER, atoi(split_line[6].c_str()));
00332
00333
00334 if (nstr > 7) data->addValue(BUS_VOLTAGE_MAG, atof(split_line[7].c_str()));
00335
00336
00337 if (nstr > 8) data->addValue(BUS_VOLTAGE_ANG, atof(split_line[8].c_str()));
00338
00339
00340 if (nstr > 9) data->addValue(BUS_VOLTAGE_MAX, atof(split_line[9].c_str()));
00341
00342
00343 if (nstr > 10) data->addValue(BUS_VOLTAGE_MIN, atof(split_line[10].c_str()));
00344
00345
00346 index++;
00347 p_istream.nextLine(line);
00348 }
00349 }
00350
00351 void find_loads()
00352 {
00353 std::string line;
00354 p_istream.nextLine(line);
00355
00356 while(test_end(line)) {
00357 std::vector<std::string> split_line;
00358 this->cleanComment(line);
00359 boost::split(split_line, line, boost::algorithm::is_any_of(","),
00360 boost::token_compress_off);
00361
00362
00363 int l_idx, o_idx;
00364 o_idx = getBusIndex(split_line[0]);
00365 if (o_idx < 0) {
00366 p_istream.nextLine(line);
00367 continue;
00368 }
00369 #ifdef OLD_MAP
00370 std::map<int, int>::iterator it;
00371 #else
00372 boost::unordered_map<int, int>::iterator it;
00373 #endif
00374 it = p_busMap.find(o_idx);
00375 if (it != p_busMap.end()) {
00376 l_idx = it->second;
00377 } else {
00378 p_istream.nextLine(line);
00379 continue;
00380 }
00381 int nstr = split_line.size();
00382
00383 int nld;
00384 if (!p_busData[l_idx]->getValue(LOAD_NUMBER, &nld)) nld = 0;
00385
00386
00387 p_busData[l_idx]->addValue(LOAD_BUSNUMBER, o_idx, nld);
00388
00389 gridpack::utility::StringUtils util;
00390 if (nstr > 1) {
00391
00392 std::string tag = util.clean2Char(split_line[1]);
00393
00394 p_busData[l_idx]->addValue(LOAD_ID, tag.c_str(), nld);
00395 }
00396
00397
00398 if (nstr > 2) p_busData[l_idx]->addValue(LOAD_STATUS,
00399 atoi(split_line[2].c_str()), nld);
00400
00401
00402 if (nstr > 3) p_busData[l_idx]->addValue(LOAD_AREA,
00403 atoi(split_line[3].c_str()), nld);
00404
00405
00406 if (nstr > 4) p_busData[l_idx]->addValue(LOAD_ZONE,
00407 atoi(split_line[4].c_str()), nld);
00408
00409
00410 if (nstr > 5) {
00411 if (nld == 0) p_busData[l_idx]->addValue(LOAD_PL, atof(split_line[5].c_str()));
00412 p_busData[l_idx]->addValue(LOAD_PL, atof(split_line[5].c_str()), nld);
00413 }
00414
00415
00416 if (nstr > 6) {
00417 if (nld == 0) p_busData[l_idx]->addValue(LOAD_QL, atof(split_line[6].c_str()));
00418 p_busData[l_idx]->addValue(LOAD_QL, atof(split_line[6].c_str()), nld);
00419 }
00420
00421
00422 if (nstr > 7) p_busData[l_idx]->addValue(LOAD_IP,
00423 atof(split_line[7].c_str()), nld);
00424
00425
00426 if (nstr > 8) p_busData[l_idx]->addValue(LOAD_IQ,
00427 atof(split_line[8].c_str()), nld);
00428
00429
00430 if (nstr > 9) p_busData[l_idx]->addValue(LOAD_YP,
00431 atof(split_line[9].c_str()), nld);
00432
00433
00434 if (nstr > 10) p_busData[l_idx]->addValue(LOAD_YQ,
00435 atoi(split_line[10].c_str()), nld);
00436
00437
00438
00439
00440 if (nld == 0) {
00441 nld = 1;
00442 p_busData[l_idx]->addValue(LOAD_NUMBER,nld);
00443 } else {
00444 nld++;
00445 p_busData[l_idx]->setValue(LOAD_NUMBER,nld);
00446 }
00447
00448 p_istream.nextLine(line);
00449 }
00450 }
00451
00452 void find_fixed_shunts()
00453 {
00454 std::string line;
00455 p_istream.nextLine(line);
00456
00457 while(test_end(line)) {
00458 std::vector<std::string> split_line;
00459 this->cleanComment(line);
00460 boost::split(split_line, line, boost::algorithm::is_any_of(","),
00461 boost::token_compress_off);
00462
00463
00464 int l_idx, o_idx;
00465 o_idx = getBusIndex(split_line[0]);
00466 #ifdef OLD_MAP
00467 std::map<int, int>::iterator it;
00468 #else
00469 boost::unordered_map<int, int>::iterator it;
00470 #endif
00471 it = p_busMap.find(o_idx);
00472 if (it != p_busMap.end()) {
00473 l_idx = it->second;
00474 } else {
00475 p_istream.nextLine(line);
00476 continue;
00477 }
00478 int nstr = split_line.size();
00479
00480
00481 int nshnt;
00482 if (!p_busData[l_idx]->getValue(SHUNT_NUMBER, &nshnt)) nshnt = 0;
00483
00484 p_busData[l_idx]->addValue(SHUNT_BUSNUMBER, o_idx, nshnt);
00485
00486 if (nstr > 1) {
00487
00488 gridpack::utility::StringUtils util;
00489 std::string tag = util.clean2Char(split_line[1]);
00490
00491 p_busData[l_idx]->addValue(SHUNT_ID, tag.c_str(), nshnt);
00492 }
00493
00494
00495 if (nstr > 2) p_busData[l_idx]->addValue(SHUNT_STATUS,
00496 atoi(split_line[2].c_str()), nshnt);
00497
00498
00499 if (nstr > 3) {
00500 if (nshnt==0) p_busData[l_idx]->addValue(BUS_SHUNT_GL,
00501 atof(split_line[3].c_str()));
00502 p_busData[l_idx]->addValue(BUS_SHUNT_GL,
00503 atof(split_line[3].c_str()),nshnt);
00504 }
00505
00506
00507 if (nstr > 4) {
00508 if (nshnt == 0) p_busData[l_idx]->addValue(BUS_SHUNT_BL,
00509 atof(split_line[4].c_str()));
00510 p_busData[l_idx]->addValue(BUS_SHUNT_BL,
00511 atof(split_line[4].c_str()),nshnt);
00512 }
00513
00514
00515 if (nshnt == 0) {
00516 nshnt = 1;
00517 p_busData[l_idx]->addValue(SHUNT_NUMBER,nshnt);
00518 } else {
00519 nshnt++;
00520 p_busData[l_idx]->setValue(SHUNT_NUMBER,nshnt);
00521 }
00522
00523 p_istream.nextLine(line);
00524 }
00525 }
00526
00527 void find_generators()
00528 {
00529 std::string line;
00530 p_istream.nextLine(line);
00531 while(test_end(line)) {
00532 std::vector<std::string> split_line;
00533 this->cleanComment(line);
00534 boost::split(split_line, line, boost::algorithm::is_any_of(","),
00535 boost::token_compress_off);
00536
00537
00538 int l_idx, o_idx;
00539 o_idx = getBusIndex(split_line[0]);
00540 #ifdef OLD_MAP
00541 std::map<int, int>::iterator it;
00542 #else
00543 boost::unordered_map<int, int>::iterator it;
00544 #endif
00545 int nstr = split_line.size();
00546 it = p_busMap.find(o_idx);
00547 if (it != p_busMap.end()) {
00548 l_idx = it->second;
00549 } else {
00550 p_istream.nextLine(line);
00551 continue;
00552 }
00553
00554
00555 int ngen;
00556 if (!p_busData[l_idx]->getValue(GENERATOR_NUMBER, &ngen)) ngen = 0;
00557
00558
00559 p_busData[l_idx]->addValue(GENERATOR_BUSNUMBER, o_idx, ngen);
00560
00561
00562 gridpack::utility::StringUtils util;
00563 std::string tag = util.clean2Char(split_line[1]);
00564
00565 p_busData[l_idx]->addValue(GENERATOR_ID, tag.c_str(), ngen);
00566
00567
00568 if (nstr > 2) p_busData[l_idx]->addValue(GENERATOR_PG, atof(split_line[2].c_str()),
00569 ngen);
00570
00571
00572 if (nstr > 3) p_busData[l_idx]->addValue(GENERATOR_QG, atof(split_line[3].c_str()),
00573 ngen);
00574
00575
00576 if (nstr > 4) p_busData[l_idx]->addValue(GENERATOR_QMAX,
00577 atof(split_line[4].c_str()), ngen);
00578
00579
00580 if (nstr > 5) p_busData[l_idx]->addValue(GENERATOR_QMIN,
00581 atof(split_line[5].c_str()), ngen);
00582
00583
00584 if (nstr > 6) p_busData[l_idx]->addValue(GENERATOR_VS, atof(split_line[6].c_str()),
00585 ngen);
00586
00587
00588 if (nstr > 7) p_busData[l_idx]->addValue(GENERATOR_IREG,
00589 atoi(split_line[7].c_str()), ngen);
00590
00591
00592 if (nstr > 8) p_busData[l_idx]->addValue(GENERATOR_MBASE,
00593 atof(split_line[8].c_str()), ngen);
00594
00595
00596 if (nstr > 10) p_busData[l_idx]->addValue(GENERATOR_ZSOURCE,
00597 gridpack::ComplexType(atof(split_line[9].c_str()),
00598 atof(split_line[10].c_str())), ngen);
00599
00600
00601 if (nstr > 12) p_busData[l_idx]->addValue(GENERATOR_XTRAN,
00602 gridpack::ComplexType(atof(split_line[11].c_str()),
00603 atof(split_line[12].c_str())), ngen);
00604
00605
00606 if (nstr > 13) p_busData[l_idx]->addValue(GENERATOR_GTAP,
00607 atof(split_line[13].c_str()), ngen);
00608
00609
00610 if (nstr > 14) p_busData[l_idx]->addValue(GENERATOR_STAT,
00611 atoi(split_line[14].c_str()), ngen);
00612
00613
00614 if (nstr > 15) p_busData[l_idx]->addValue(GENERATOR_RMPCT,
00615 atof(split_line[15].c_str()), ngen);
00616
00617
00618 if (nstr > 16) p_busData[l_idx]->addValue(GENERATOR_PMAX,
00619 atof(split_line[16].c_str()), ngen);
00620
00621
00622 if (nstr > 17) p_busData[l_idx]->addValue(GENERATOR_PMIN,
00623 atof(split_line[17].c_str()), ngen);
00624
00625
00626
00627
00628
00629 if (nstr > 18) {
00630 int owner = 0;
00631 if (this->isBlank(split_line[18])) {
00632 p_busData[l_idx]->getValue(BUS_OWNER,&owner);
00633 } else {
00634 owner = atoi(split_line[18].c_str());
00635 }
00636 p_busData[l_idx]->addValue(GENERATOR_OWNER1, owner, ngen);
00637 double frac = 1.0;
00638 if (nstr > 19) {
00639 if (!this->isBlank(split_line[19])) {
00640 frac = atof(split_line[19].c_str());
00641 }
00642 }
00643 p_busData[l_idx]->addValue(GENERATOR_OFRAC1, frac, ngen);
00644 }
00645 if (nstr > 20) {
00646 int owner = 0;
00647 if (this->isBlank(split_line[20])) {
00648 owner = 0;
00649 } else {
00650 owner = atoi(split_line[20].c_str());
00651 }
00652 p_busData[l_idx]->addValue(GENERATOR_OWNER2, owner, ngen);
00653 double frac = 0.0;
00654 if (nstr > 21) {
00655 if (!this->isBlank(split_line[21])) {
00656 frac = atof(split_line[21].c_str());
00657 }
00658 }
00659 p_busData[l_idx]->addValue(GENERATOR_OFRAC2, frac, ngen);
00660 }
00661 if (nstr > 22) {
00662 int owner = 0;
00663 if (this->isBlank(split_line[22])) {
00664 owner = 0;
00665 } else {
00666 owner = atoi(split_line[22].c_str());
00667 }
00668 p_busData[l_idx]->addValue(GENERATOR_OWNER3, owner, ngen);
00669 double frac = 0.0;
00670 if (nstr > 23) {
00671 if (!this->isBlank(split_line[23])) {
00672 frac = atof(split_line[23].c_str());
00673 }
00674 }
00675 p_busData[l_idx]->addValue(GENERATOR_OFRAC3, frac, ngen);
00676 }
00677 if (nstr > 24) {
00678 int owner = 0;
00679 if (this->isBlank(split_line[24])) {
00680 owner = 0;
00681 } else {
00682 owner = atoi(split_line[24].c_str());
00683 }
00684 p_busData[l_idx]->addValue(GENERATOR_OWNER4, owner, ngen);
00685 double frac = 0.0;
00686 if (nstr > 25) {
00687 if (!this->isBlank(split_line[25])) {
00688 frac = atof(split_line[25].c_str());
00689 }
00690 }
00691 p_busData[l_idx]->addValue(GENERATOR_OFRAC4, frac, ngen);
00692 }
00693
00694
00695 if (nstr > 26) {
00696 p_busData[l_idx]->addValue(GENERATOR_WMOD,
00697 atoi(split_line[26].c_str()), ngen);
00698 }
00699 if (nstr > 27) {
00700 p_busData[l_idx]->addValue(GENERATOR_WPF,
00701 atof(split_line[27].c_str()), ngen);
00702 }
00703
00704
00705 if (ngen == 0) {
00706 ngen = 1;
00707 p_busData[l_idx]->addValue(GENERATOR_NUMBER,ngen);
00708 } else {
00709 ngen++;
00710 p_busData[l_idx]->setValue(GENERATOR_NUMBER,ngen);
00711 }
00712
00713 p_istream.nextLine(line);
00714 }
00715 }
00716
00717 void find_branches()
00718 {
00719 std::string line;
00720 int o_idx1, o_idx2;
00721 int index = 0;
00722
00723 p_istream.nextLine(line);
00724
00725 int nelems;
00726 while(test_end(line)) {
00727 std::pair<int, int> branch_pair;
00728 std::vector<std::string> split_line;
00729 this->cleanComment(line);
00730 boost::split(split_line, line, boost::algorithm::is_any_of(","),
00731 boost::token_compress_off);
00732
00733 o_idx1 = getBusIndex(split_line[0]);
00734 o_idx2 = getBusIndex(split_line[1]);
00735
00736
00737 int l_idx = 0;
00738 branch_pair = std::pair<int,int>(o_idx1, o_idx2);
00739 #ifdef OLD_MAP
00740 std::map<std::pair<int, int>, int>::iterator it;
00741 #else
00742 boost::unordered_map<std::pair<int, int>, int>::iterator it;
00743 #endif
00744 it = p_branchMap.find(branch_pair);
00745
00746 bool switched = false;
00747 if (it != p_branchMap.end()) {
00748 l_idx = it->second;
00749 p_branchData[l_idx]->getValue(BRANCH_NUM_ELEMENTS,&nelems);
00750 } else {
00751
00752 std::pair<int, int> new_branch_pair;
00753 new_branch_pair = std::pair<int,int>(o_idx2, o_idx1);
00754 it = p_branchMap.find(new_branch_pair);
00755 if (it != p_branchMap.end()) {
00756
00757
00758 l_idx = it->second;
00759 p_branchData[l_idx]->getValue(BRANCH_NUM_ELEMENTS,&nelems);
00760 switched = true;
00761 } else {
00762 boost::shared_ptr<gridpack::component::DataCollection>
00763 data(new gridpack::component::DataCollection);
00764 l_idx = p_branchData.size();
00765 p_branchData.push_back(data);
00766 nelems = 0;
00767 p_branchData[l_idx]->addValue(BRANCH_NUM_ELEMENTS,nelems);
00768 }
00769 }
00770
00771 if (nelems == 0) {
00772
00773 p_branchData[l_idx]->addValue(BRANCH_INDEX, index);
00774
00775
00776 p_branchData[l_idx]->addValue(BRANCH_FROMBUS, o_idx1);
00777
00778
00779 p_branchData[l_idx]->addValue(BRANCH_TOBUS, o_idx2);
00780
00781
00782 p_branchMap.insert(std::pair<std::pair<int, int>, int >(branch_pair,
00783 index));
00784 index++;
00785 }
00786
00787
00788 p_branchData[l_idx]->addValue(BRANCH_SWITCHED, switched, nelems);
00789
00790 int nstr = split_line.size();
00791
00792 gridpack::utility::StringUtils util;
00793 std::string tag = util.clean2Char(split_line[2]);
00794
00795 if (nstr > 2) p_branchData[l_idx]->addValue(BRANCH_CKT,
00796 tag.c_str(), nelems);
00797
00798
00799 if (nstr > 3) p_branchData[l_idx]->addValue(BRANCH_R,
00800 atof(split_line[3].c_str()), nelems);
00801
00802
00803 if (nstr > 4) p_branchData[l_idx]->addValue(BRANCH_X,
00804 atof(split_line[4].c_str()), nelems);
00805
00806
00807 if (nstr > 5) p_branchData[l_idx]->addValue(BRANCH_B,
00808 atof(split_line[5].c_str()), nelems);
00809
00810
00811 if (nstr > 6) p_branchData[l_idx]->addValue(BRANCH_RATING_A,
00812 atof(split_line[6].c_str()), nelems);
00813
00814
00815 if (nstr > 7) p_branchData[l_idx]->addValue(BRANCH_RATING_B,
00816 atof(split_line[7].c_str()), nelems);
00817
00818
00819 if (nstr > 8) p_branchData[l_idx]->addValue(BRANCH_RATING_C,
00820 atof(split_line[8].c_str()), nelems);
00821
00822
00823 if (nstr > 9) p_branchData[l_idx]->addValue(BRANCH_SHUNT_ADMTTNC_G1,
00824 atof(split_line[9].c_str()), nelems);
00825
00826
00827 if (nstr > 10) p_branchData[l_idx]->addValue(BRANCH_SHUNT_ADMTTNC_B1,
00828 atof(split_line[10].c_str()), nelems);
00829
00830
00831 if (nstr > 11) p_branchData[l_idx]->addValue(BRANCH_SHUNT_ADMTTNC_G2,
00832 atof(split_line[11].c_str()), nelems);
00833
00834
00835 if (nstr > 12) p_branchData[l_idx]->addValue(BRANCH_SHUNT_ADMTTNC_B2,
00836 atof(split_line[12].c_str()), nelems);
00837
00838
00839 if (nstr > 13) p_branchData[l_idx]->addValue(BRANCH_STATUS,
00840 atoi(split_line[13].c_str()), nelems);
00841
00842
00843 if (nstr > 14) p_branchData[l_idx]->addValue(BRANCH_METER,
00844 atoi(split_line[14].c_str()), nelems);
00845
00846
00847 if (nstr > 15) p_branchData[l_idx]->addValue(BRANCH_LENGTH,
00848 atof(split_line[15].c_str()), nelems);
00849
00850
00851 if (nstr > 16) p_branchData[l_idx]->addValue(BRANCH_O1,
00852 atoi(split_line[16].c_str()), nelems);
00853
00854
00855 if (nstr > 17) p_branchData[l_idx]->addValue(BRANCH_F1,
00856 atoi(split_line[17].c_str()), nelems);
00857
00858
00859 if (nstr > 18) p_branchData[l_idx]->addValue(BRANCH_O2,
00860 atoi(split_line[18].c_str()), nelems);
00861
00862
00863 if (nstr > 19) p_branchData[l_idx]->addValue(BRANCH_F2,
00864 atoi(split_line[19].c_str()), nelems);
00865
00866
00867 if (nstr > 20) p_branchData[l_idx]->addValue(BRANCH_O3,
00868 atoi(split_line[20].c_str()), nelems);
00869
00870
00871 if (nstr > 21) p_branchData[l_idx]->addValue(BRANCH_F3,
00872 atoi(split_line[21].c_str()), nelems);
00873
00874
00875 if (nstr > 22) p_branchData[l_idx]->addValue(BRANCH_O4,
00876 atoi(split_line[22].c_str()), nelems);
00877
00878
00879 if (nstr > 23) p_branchData[l_idx]->addValue(BRANCH_F4,
00880 atoi(split_line[23].c_str()), nelems);
00881
00882
00883
00884
00885 p_branchData[l_idx]->addValue(BRANCH_TAP,0.0,nelems);
00886
00887
00888 p_branchData[l_idx]->addValue(BRANCH_SHIFT,0.0,nelems);
00889
00890 nelems++;
00891 p_branchData[l_idx]->setValue(BRANCH_NUM_ELEMENTS,nelems);
00892 p_istream.nextLine(line);
00893 }
00894 }
00895
00896
00897 bool parse3WindXForm(std::vector<std::string>split_line, double *windv,
00898 double* ang, double *ratea, double *rateb, double *ratec)
00899 {
00900 *windv = atof(split_line[0].c_str());
00901 *ang = atof(split_line[2].c_str());
00902 *ratea = atof(split_line[3].c_str());
00903 *rateb = atof(split_line[4].c_str());
00904 *ratec = atof(split_line[5].c_str());
00905 bool ret = true;
00906 return ret && (split_line.size() > 5);
00907 }
00908
00909
00910
00911
00912 void find_transformer()
00913 {
00914 std::string line;
00915
00916 p_istream.nextLine(line);
00917
00918 std::pair<int, int> branch_pair;
00919
00920
00921 int index = p_branchData.size();
00922
00923 bool wind3X = true;
00924
00925 while(test_end(line)) {
00926 std::vector<std::string> split_line;
00927 this->cleanComment(line);
00928 boost::split(split_line, line, boost::algorithm::is_any_of(","),
00929 boost::token_compress_off);
00930 int o_idx1, o_idx2;
00931 o_idx1 = getBusIndex(split_line[0]);
00932 o_idx2 = getBusIndex(split_line[1]);
00933
00934
00935 int k = getBusIndex(split_line[2]);
00936 if (k != 0) {
00937 if (wind3X) {
00938 int o_idx3 = k;
00939 p_istream.nextLine(line);
00940 std::vector<std::string> split_line2;
00941 this->cleanComment(line);
00942 boost::split(split_line2, line, boost::algorithm::is_any_of(","),
00943 boost::token_compress_off);
00944
00945 int stat;
00946 stat = atoi(split_line[11].c_str());
00947 if (split_line2.size() < 4 || stat == 0) {
00948 p_istream.nextLine(line);
00949 p_istream.nextLine(line);
00950 p_istream.nextLine(line);
00951 p_istream.nextLine(line);
00952 continue;
00953 }
00954
00955 int l_idx1, l_idx2, l_idx3;
00956 std::map<int,int>::iterator it;
00957 it = p_busMap.find(o_idx1);
00958 if (it != p_busMap.end()) {
00959 l_idx1 = it->second;
00960 } else {
00961 printf("No match found for bus %s\n",split_line[0].c_str());
00962 }
00963 it = p_busMap.find(o_idx2);
00964 if (it != p_busMap.end()) {
00965 l_idx2 = it->second;
00966 } else {
00967 printf("No match found for bus %s\n",split_line[1].c_str());
00968 }
00969 it = p_busMap.find(o_idx3);
00970 if (it != p_busMap.end()) {
00971 l_idx3 = it->second;
00972 } else {
00973 printf("No match found for bus %s\n",split_line[2].c_str());
00974 }
00975
00976
00977
00978
00979
00980 boost::shared_ptr<gridpack::component::DataCollection>
00981 data(new gridpack::component::DataCollection);
00982 int n_idx = p_busData.size();
00983 p_busData.push_back(data);
00984 p_maxBusIndex++;
00985 data->addValue(BUS_NUMBER,p_maxBusIndex);
00986 char cbuf[128];
00987 sprintf(cbuf,"DUMMY_BUS-%d-%d-%d",o_idx1,o_idx2,o_idx3);
00988 data->addValue(BUS_NAME,cbuf);
00989 data->addValue(BUS_BASEKV,0.0);
00990 data->addValue(BUS_TYPE,1);
00991 int ival;
00992 p_busData[l_idx1]->getValue(BUS_AREA,&ival);
00993 data->addValue(BUS_AREA,ival);
00994 p_busData[l_idx1]->getValue(BUS_OWNER,&ival);
00995 data->addValue(BUS_OWNER, ival);
00996 double rval = 0.0;
00997 double rvol;
00998 p_busData[l_idx1]->getValue(BUS_VOLTAGE_MAG,&rvol);
00999 rval += rvol;
01000 p_busData[l_idx2]->getValue(BUS_VOLTAGE_MAG,&rvol);
01001 rval += rvol;
01002 p_busData[l_idx3]->getValue(BUS_VOLTAGE_MAG,&rvol);
01003 rval += rvol;
01004 rval = rval/3.0;
01005 rval = 1.0;
01006 data->addValue(BUS_VOLTAGE_MAG,rval);
01007 rval = 0.0;
01008 p_busData[l_idx1]->getValue(BUS_VOLTAGE_ANG,&rvol);
01009 rval += rvol;
01010 p_busData[l_idx2]->getValue(BUS_VOLTAGE_ANG,&rvol);
01011 rval += rvol;
01012 p_busData[l_idx3]->getValue(BUS_VOLTAGE_ANG,&rvol);
01013 rval += rvol;
01014 rval = rval/3.0;
01015 rval = 0.0;
01016 data->addValue(BUS_VOLTAGE_ANG,rval);
01017
01018
01019 double mag1, mag2;
01020 mag1 = atof(split_line[7].c_str());
01021 mag2 = atof(split_line[8].c_str());
01022
01023 gridpack::utility::StringUtils util;
01024 std::string tag = util.clean2Char(split_line[3]);
01025
01026
01027 double r12, r23, r31, x12, x23, x31, sb12, sb23, sb31;
01028 double r1, r2, r3, x1, x2, x3, b1, b2, b3;
01029 r12 = atof(split_line2[0].c_str());
01030 x12 = atof(split_line2[1].c_str());
01031 sb12 = atof(split_line2[2].c_str());
01032 r23 = atof(split_line2[3].c_str());
01033 x23 = atof(split_line2[4].c_str());
01034 sb23 = atof(split_line2[5].c_str());
01035 r31 = atof(split_line2[6].c_str());
01036 x31 = atof(split_line2[7].c_str());
01037 sb31 = atof(split_line2[8].c_str());
01038 r1 = 0.5*(r12+r31-r23);
01039 x1 = 0.5*(x12+x31-x23);
01040 b1 = 0.0;
01041 r2 = 0.5*(r12+r23-r31);
01042 x2 = 0.5*(x12+x23-x31);
01043 b2 = 0.0;
01044 r3 = 0.5*(r23+r31-r12);
01045 x3 = 0.5*(x23+x31-x12);
01046 b3 = 0.0;
01047
01048 if (sb12 != p_case_sbase && sb12 == 0.0) {
01049 r1 = r1*p_case_sbase/sb12;
01050 x1 = x1*p_case_sbase/sb12;
01051 }
01052 if (sb23 != p_case_sbase && sb23 == 0.0) {
01053 r2 = r2*p_case_sbase/sb23;
01054 x2 = x2*p_case_sbase/sb23;
01055 }
01056 if (sb31 != p_case_sbase && sb31 == 0.0) {
01057 r3 = r3*p_case_sbase/sb31;
01058 x3 = x3*p_case_sbase/sb31;
01059 }
01060
01061
01062 int index = p_branchData.size();
01063 boost::shared_ptr<gridpack::component::DataCollection>
01064 data1(new gridpack::component::DataCollection);
01065 p_branchData.push_back(data1);
01066 p_istream.nextLine(line);
01067 std::vector<std::string> split_line3;
01068 this->cleanComment(line);
01069 boost::split(split_line3, line, boost::algorithm::is_any_of(","),
01070 boost::token_compress_off);
01071 double windv, ang, ratea, rateb, ratec;
01072 parse3WindXForm(split_line3, &windv, &ang, &ratea, &rateb, &ratec);
01073 data1->addValue(BRANCH_INDEX,index);
01074 data1->addValue(BRANCH_FROMBUS,o_idx1);
01075 data1->addValue(BRANCH_TOBUS,p_maxBusIndex);
01076 data1->addValue(BRANCH_NUM_ELEMENTS,1);
01077 data1->addValue(BRANCH_CKT,tag.c_str(),0);
01078 data1->addValue(BRANCH_R,r1,0);
01079 data1->addValue(BRANCH_X,x1,0);
01080 data1->addValue(BRANCH_B,b1,0);
01081 data1->addValue(BRANCH_RATING_A,ratea,0);
01082 data1->addValue(BRANCH_RATING_B,rateb,0);
01083 data1->addValue(BRANCH_RATING_C,ratec,0);
01084 data1->addValue(BRANCH_TAP,windv,0);
01085 data1->addValue(BRANCH_SHIFT,ang,0);
01086 data1->addValue(BRANCH_SWITCHED,false,0);
01087 data1->addValue(BRANCH_SHUNT_ADMTTNC_G1,mag1,0);
01088 data1->addValue(BRANCH_SHUNT_ADMTTNC_B1,mag2,0);
01089 data1->addValue(BRANCH_SHUNT_ADMTTNC_G2,0.0,0);
01090 data1->addValue(BRANCH_SHUNT_ADMTTNC_B2,0.0,0);
01091 if (stat == 1 || stat == 2 || stat == 3) {
01092 data1->addValue(BRANCH_STATUS,1,0);
01093 } else {
01094 data1->addValue(BRANCH_STATUS,0,0);
01095 }
01096
01097
01098 index++;
01099 boost::shared_ptr<gridpack::component::DataCollection>
01100 data2(new gridpack::component::DataCollection);
01101 p_branchData.push_back(data2);
01102 p_istream.nextLine(line);
01103 std::vector<std::string> split_line4;
01104 this->cleanComment(line);
01105 boost::split(split_line4, line, boost::algorithm::is_any_of(","),
01106 boost::token_compress_off);
01107 parse3WindXForm(split_line4, &windv, &ang, &ratea, &rateb, &ratec);
01108 data2->addValue(BRANCH_INDEX,index);
01109 data2->addValue(BRANCH_FROMBUS,o_idx2);
01110 data2->addValue(BRANCH_TOBUS,p_maxBusIndex);
01111 data2->addValue(BRANCH_NUM_ELEMENTS,1);
01112 data2->addValue(BRANCH_CKT,tag.c_str(),0);
01113 data2->addValue(BRANCH_R,r2,0);
01114 data2->addValue(BRANCH_X,x2,0);
01115 data2->addValue(BRANCH_B,b2,0);
01116 data2->addValue(BRANCH_RATING_A,ratea,0);
01117 data2->addValue(BRANCH_RATING_B,rateb,0);
01118 data2->addValue(BRANCH_RATING_C,ratec,0);
01119 data2->addValue(BRANCH_TAP,windv,0);
01120 data2->addValue(BRANCH_SHIFT,ang,0);
01121 data2->addValue(BRANCH_SWITCHED,false,0);
01122 data2->addValue(BRANCH_SHUNT_ADMTTNC_G1,0.0,0);
01123 data2->addValue(BRANCH_SHUNT_ADMTTNC_B1,0.0,0);
01124 data2->addValue(BRANCH_SHUNT_ADMTTNC_G2,0.0,0);
01125 data2->addValue(BRANCH_SHUNT_ADMTTNC_B2,0.0,0);
01126 if (stat == 1 || stat == 3 || stat == 4) {
01127 data2->addValue(BRANCH_STATUS,1,0);
01128 } else {
01129 data2->addValue(BRANCH_STATUS,0,0);
01130 }
01131
01132
01133 index++;
01134 boost::shared_ptr<gridpack::component::DataCollection>
01135 data3(new gridpack::component::DataCollection);
01136 p_branchData.push_back(data3);
01137 p_istream.nextLine(line);
01138 std::vector<std::string> split_line5;
01139 this->cleanComment(line);
01140 boost::split(split_line5, line, boost::algorithm::is_any_of(","),
01141 boost::token_compress_off);
01142 parse3WindXForm(split_line5, &windv, &ang, &ratea, &rateb, &ratec);
01143 data3->addValue(BRANCH_INDEX,index);
01144 data3->addValue(BRANCH_FROMBUS,o_idx3);
01145 data3->addValue(BRANCH_TOBUS,p_maxBusIndex);
01146 data3->addValue(BRANCH_NUM_ELEMENTS,1);
01147 data3->addValue(BRANCH_CKT,tag.c_str(),0);
01148 data3->addValue(BRANCH_R,r3,0);
01149 data3->addValue(BRANCH_X,x3,0);
01150 data3->addValue(BRANCH_B,b3,0);
01151 data3->addValue(BRANCH_RATING_A,ratea,0);
01152 data3->addValue(BRANCH_RATING_B,rateb,0);
01153 data3->addValue(BRANCH_RATING_C,ratec,0);
01154 data3->addValue(BRANCH_TAP,windv,0);
01155 data3->addValue(BRANCH_SHIFT,ang,0);
01156 data3->addValue(BRANCH_SWITCHED,false,0);
01157 data3->addValue(BRANCH_SHUNT_ADMTTNC_G1,0.0,0);
01158 data3->addValue(BRANCH_SHUNT_ADMTTNC_B1,0.0,0);
01159 data3->addValue(BRANCH_SHUNT_ADMTTNC_G2,0.0,0);
01160 data3->addValue(BRANCH_SHUNT_ADMTTNC_B2,0.0,0);
01161 if (stat == 1 || stat == 2 || stat == 4) {
01162 data3->addValue(BRANCH_STATUS,1,0);
01163 } else {
01164 data3->addValue(BRANCH_STATUS,0,0);
01165 }
01166 } else {
01167
01168 p_istream.nextLine(line);
01169 p_istream.nextLine(line);
01170 p_istream.nextLine(line);
01171 p_istream.nextLine(line);
01172 continue;
01173 }
01174 } else {
01175 int ntoken = split_line.size();
01176 p_istream.nextLine(line);
01177 std::vector<std::string> split_line2;
01178 this->cleanComment(line);
01179 boost::split(split_line2, line, boost::algorithm::is_any_of(","),
01180 boost::token_compress_off);
01181
01182 p_istream.nextLine(line);
01183 std::vector<std::string> split_line3;
01184 this->cleanComment(line);
01185 boost::split(split_line3, line, boost::algorithm::is_any_of(","),
01186 boost::token_compress_off);
01187
01188 p_istream.nextLine(line);
01189 std::vector<std::string> split_line4;
01190 this->cleanComment(line);
01191 boost::split(split_line4, line, boost::algorithm::is_any_of(","),
01192 boost::token_compress_off);
01193
01194
01195 int l_idx = 0;
01196 branch_pair = std::pair<int,int>(o_idx1, o_idx2);
01197 #ifdef OLD_MAP
01198 std::map<std::pair<int, int>, int>::iterator it;
01199 #else
01200 boost::unordered_map<std::pair<int, int>, int>::iterator it;
01201 #endif
01202 it = p_branchMap.find(branch_pair);
01203 bool switched = false;
01204 int nelems;
01205 if (it != p_branchMap.end()) {
01206 l_idx = it->second;
01207 p_branchData[l_idx]->getValue(BRANCH_NUM_ELEMENTS,&nelems);
01208 } else {
01209
01210 std::pair<int, int> new_branch_pair;
01211 new_branch_pair = std::pair<int,int>(o_idx2, o_idx1);
01212 it = p_branchMap.find(new_branch_pair);
01213 if (it != p_branchMap.end()) {
01214 l_idx = it->second;
01215 p_branchData[l_idx]->getValue(BRANCH_NUM_ELEMENTS,&nelems);
01216 switched = true;
01217 } else {
01218 boost::shared_ptr<gridpack::component::DataCollection>
01219 data(new gridpack::component::DataCollection);
01220 l_idx = p_branchData.size();
01221 p_branchData.push_back(data);
01222 std::pair<std::pair<int,int>,int> item;
01223 item = std::pair<std::pair<int,int>,int>(branch_pair,l_idx);
01224 p_branchMap.insert(item);
01225 nelems = 0;
01226 p_branchData[l_idx]->addValue(BRANCH_NUM_ELEMENTS,nelems);
01227 }
01228 }
01229
01230
01231
01232 if (nelems == 0) {
01233
01234 p_branchData[l_idx]->addValue(BRANCH_INDEX,
01235 index);
01236
01237
01238 p_branchData[l_idx]->addValue(BRANCH_FROMBUS,
01239 o_idx1);
01240
01241
01242 p_branchData[l_idx]->addValue(BRANCH_TOBUS,
01243 o_idx2);
01244
01245
01246 p_branchMap.insert(std::pair<std::pair<int,int>,int >
01247 (branch_pair, index));
01248 index++;
01249 }
01250
01251
01252 gridpack::utility::StringUtils util;
01253 std::string tag = util.clean2Char(split_line[3]);
01254
01255 p_branchData[l_idx]->addValue(BRANCH_CKT, tag.c_str(), nelems);
01256
01257
01258
01259
01260
01261
01262 p_branchData[l_idx]->addValue(TRANSFORMER_CW,
01263 atoi(split_line[4].c_str()),nelems);
01264
01265
01266
01267
01268
01269 p_branchData[l_idx]->addValue(TRANSFORMER_CZ,
01270 atoi(split_line[5].c_str()),nelems);
01271
01272
01273
01274
01275
01276 p_branchData[l_idx]->addValue(TRANSFORMER_CM,
01277 atoi(split_line[6].c_str()),nelems);
01278
01279
01280
01281
01282
01283 p_branchData[l_idx]->addValue(TRANSFORMER_MAG1,
01284 atof(split_line[7].c_str()),nelems);
01285
01286
01287
01288
01289
01290 p_branchData[l_idx]->addValue(TRANSFORMER_MAG2,
01291 atof(split_line[8].c_str()),nelems);
01292
01293
01294
01295
01296
01297 p_branchData[l_idx]->addValue(BRANCH_STATUS,
01298 atoi(split_line[11].c_str()),nelems);
01299
01300
01301
01302
01303
01304 p_branchData[l_idx]->addValue(TRANSFORMER_NMETR,
01305 atoi(split_line[9].c_str()),nelems);
01306
01307
01308
01309
01310
01311 if (ntoken > 12) p_branchData[l_idx]->addValue(BRANCH_O1,
01312 atoi(split_line[12].c_str()), nelems);
01313
01314
01315
01316
01317
01318 if (ntoken > 13) p_branchData[l_idx]->addValue(BRANCH_F1,
01319 atoi(split_line[13].c_str()), nelems);
01320
01321
01322
01323
01324
01325 if (ntoken > 14) p_branchData[l_idx]->addValue(BRANCH_O2,
01326 atoi(split_line[14].c_str()), nelems);
01327
01328
01329
01330
01331
01332 if (ntoken > 15) p_branchData[l_idx]->addValue(BRANCH_F2,
01333 atoi(split_line[15].c_str()), nelems);
01334
01335
01336
01337
01338
01339 if (ntoken > 16) p_branchData[l_idx]->addValue(BRANCH_O3,
01340 atoi(split_line[16].c_str()), nelems);
01341
01342
01343
01344
01345
01346 if (ntoken > 17) p_branchData[l_idx]->addValue(BRANCH_F3,
01347 atoi(split_line[17].c_str()), nelems);
01348
01349
01350
01351
01352
01353 if (ntoken > 18) p_branchData[l_idx]->addValue(BRANCH_O4,
01354 atoi(split_line[18].c_str()), nelems);
01355
01356
01357
01358
01359
01360 if (ntoken > 19) p_branchData[l_idx]->addValue(BRANCH_F4,
01361 atoi(split_line[19].c_str()), nelems);
01362
01363
01364
01365
01366
01367
01368
01369 double sbase2 = atof(split_line2[2].c_str());
01370 p_branchData[l_idx]->addValue(TRANSFORMER_SBASE1_2,sbase2,nelems);
01371
01372
01373
01374
01375
01376 double rval = atof(split_line2[0].c_str());
01377 if (sbase2 == p_case_sbase || sbase2 == 0.0) {
01378 p_branchData[l_idx]->addValue(BRANCH_R,rval,nelems);
01379 } else {
01380 rval = rval*p_case_sbase/sbase2;
01381 p_branchData[l_idx]->addValue(BRANCH_R,rval,nelems);
01382 }
01383 p_branchData[l_idx]->addValue(TRANSFORMER_R1_2,rval,nelems);
01384
01385
01386
01387
01388
01389 rval = atof(split_line2[1].c_str());
01390 if (sbase2 == p_case_sbase || sbase2 == 0.0) {
01391 p_branchData[l_idx]->addValue(BRANCH_X,rval,nelems);
01392 } else {
01393 rval = rval*p_case_sbase/sbase2;
01394 p_branchData[l_idx]->addValue(BRANCH_X,rval,nelems);
01395 }
01396 p_branchData[l_idx]->addValue(TRANSFORMER_X1_2,rval,nelems);
01397
01398
01399
01400
01401
01402
01403 double windv1 = atof(split_line3[0].c_str());
01404 double windv2 = atof(split_line4[0].c_str());
01405 double tap = windv1/windv2;
01406 p_branchData[l_idx]->addValue(BRANCH_TAP,tap,nelems);
01407 p_branchData[l_idx]->addValue(TRANSFORMER_WINDV1,windv1,nelems);
01408 p_branchData[l_idx]->addValue(TRANSFORMER_WINDV2,windv2,nelems);
01409
01410
01411
01412
01413
01414 p_branchData[l_idx]->addValue(BRANCH_SHIFT,
01415 atof(split_line3[2].c_str()),nelems);
01416 p_branchData[l_idx]->addValue(TRANSFORMER_ANG1,
01417 atof(split_line3[2].c_str()),nelems);
01418
01419
01420
01421
01422
01423 p_branchData[l_idx]->addValue(BRANCH_RATING_A,
01424 atof(split_line3[3].c_str()),nelems);
01425
01426
01427
01428
01429
01430 p_branchData[l_idx]->addValue(BRANCH_RATING_B,
01431 atof(split_line3[4].c_str()),nelems);
01432
01433
01434
01435
01436
01437 p_branchData[l_idx]->addValue(BRANCH_RATING_C,
01438 atof(split_line3[5].c_str()),nelems);
01439
01440
01441
01442
01443
01444 p_branchData[l_idx]->addValue(TRANSFORMER_CODE1,
01445 atoi(split_line3[6].c_str()),nelems);
01446
01447
01448
01449
01450
01451 p_branchData[l_idx]->addValue(TRANSFORMER_RMA,
01452 atof(split_line3[8].c_str()),nelems);
01453
01454
01455
01456
01457
01458 p_branchData[l_idx]->addValue(TRANSFORMER_RMI,
01459 atof(split_line3[9].c_str()),nelems);
01460
01461
01462
01463
01464
01465 p_branchData[l_idx]->addValue(TRANSFORMER_VMA,
01466 atof(split_line3[10].c_str()),nelems);
01467
01468
01469
01470
01471
01472 p_branchData[l_idx]->addValue(TRANSFORMER_VMI,
01473 atof(split_line3[11].c_str()),nelems);
01474
01475
01476
01477
01478
01479 p_branchData[l_idx]->addValue(TRANSFORMER_NTP,
01480 atoi(split_line3[12].c_str()),nelems);
01481
01482
01483
01484
01485
01486 p_branchData[l_idx]->addValue(TRANSFORMER_TAB,
01487 atoi(split_line3[13].c_str()),nelems);
01488
01489
01490
01491
01492
01493 p_branchData[l_idx]->addValue(TRANSFORMER_CR,
01494 atof(split_line3[14].c_str()),nelems);
01495
01496
01497
01498
01499
01500 p_branchData[l_idx]->addValue(TRANSFORMER_CX,
01501 atof(split_line3[15].c_str()),nelems);
01502
01503
01504
01505
01506
01507 p_branchData[l_idx]->addValue(TRANSFORMER_CNXA,
01508 atof(split_line3[16].c_str()),nelems);
01509
01510 nelems++;
01511 p_branchData[l_idx]->setValue(BRANCH_NUM_ELEMENTS,nelems);
01512 }
01513 p_istream.nextLine(line);
01514 }
01515 }
01516
01517 void find_area()
01518 {
01519 std::string line;
01520
01521 p_istream.nextLine(line);
01522
01523 int ncnt = 0;
01524 while(test_end(line)) {
01525 std::vector<std::string> split_line;
01526 this->cleanComment(line);
01527 boost::split(split_line, line, boost::algorithm::is_any_of(","),
01528 boost::token_compress_off);
01529
01530
01531 p_network_data->addValue(AREAINTG_ISW, atoi(split_line[1].c_str()),ncnt);
01532
01533
01534 p_network_data->addValue(AREAINTG_NUMBER, atoi(split_line[0].c_str()),ncnt);
01535
01536
01537 p_network_data->addValue(AREAINTG_PDES, atof(split_line[2].c_str()),ncnt);
01538
01539
01540 p_network_data->addValue(AREAINTG_PTOL, atof(split_line[3].c_str()),ncnt);
01541
01542
01543 p_network_data->addValue(AREAINTG_NAME, split_line[4].c_str(),ncnt);
01544 ncnt++;
01545
01546 p_istream.nextLine(line);
01547 }
01548 p_network_data->addValue(AREA_TOTAL,ncnt);
01549 }
01550
01551 void find_2term()
01552 {
01553 std::string line;
01554
01555 p_istream.nextLine(line);
01556
01557 while(test_end(line)) {
01558 std::vector<std::string> split_line;
01559 this->cleanComment(line);
01560 boost::split(split_line, line, boost::algorithm::is_any_of(","),
01561 boost::token_compress_off);
01562 int l_idx, o_idx;
01563 o_idx = atoi(split_line[1].c_str());
01564 #ifdef OLD_MAP
01565 std::map<int, int>::iterator it;
01566 #else
01567 boost::unordered_map<int, int>::iterator it;
01568 #endif
01569 it = p_busMap.find(o_idx);
01570 if (it != p_busMap.end()) {
01571 l_idx = it->second;
01572 } else {
01573 p_istream.nextLine(line);
01574 continue;
01575 }
01576
01577 p_istream.nextLine(line);
01578 }
01579 }
01580
01581 void find_vsc_line()
01582 {
01583 std::string line;
01584
01585 p_istream.nextLine(line);
01586
01587 while(test_end(line)) {
01588 std::vector<std::string> split_line;
01589 this->cleanComment(line);
01590 boost::split(split_line, line, boost::algorithm::is_any_of(","),
01591 boost::token_compress_off);
01592
01593 p_istream.nextLine(line);
01594 }
01595 }
01596
01597
01598
01599
01600
01601 void find_switched_shunt()
01602 {
01603 std::string line;
01604
01605 p_istream.nextLine(line);
01606 while(test_end(line)) {
01607 std::vector<std::string> split_line;
01608 this->cleanComment(line);
01609 boost::split(split_line, line, boost::algorithm::is_any_of(","),
01610 boost::token_compress_off);
01611
01612
01613
01614
01615
01616 int l_idx, o_idx;
01617 l_idx = atoi(split_line[0].c_str());
01618 #ifdef OLD_MAP
01619 std::map<int, int>::iterator it;
01620 #else
01621 boost::unordered_map<int, int>::iterator it;
01622 #endif
01623 it = p_busMap.find(l_idx);
01624 if (it != p_busMap.end()) {
01625 o_idx = it->second;
01626 } else {
01627 p_istream.nextLine(line);
01628 continue;
01629 }
01630 int nval = split_line.size();
01631
01632 p_busData[o_idx]->addValue(SWSHUNT_BUSNUMBER, atoi(split_line[0].c_str()));
01633
01634
01635
01636
01637
01638 p_busData[o_idx]->addValue(SHUNT_MODSW, atoi(split_line[1].c_str()));
01639
01640
01641
01642
01643
01644 p_busData[o_idx]->addValue(SHUNT_ADJM, atoi(split_line[2].c_str()));
01645
01646
01647
01648
01649
01650 p_busData[o_idx]->addValue(SHUNT_SWCH_STAT, atoi(split_line[3].c_str()));
01651
01652
01653
01654
01655
01656 p_busData[o_idx]->addValue(SHUNT_VSWHI, atof(split_line[4].c_str()));
01657
01658
01659
01660
01661
01662 p_busData[o_idx]->addValue(SHUNT_VSWLO, atof(split_line[5].c_str()));
01663
01664
01665
01666
01667
01668 p_busData[o_idx]->addValue(SHUNT_SWREM, atoi(split_line[6].c_str()));
01669
01670
01671
01672
01673
01674 p_busData[o_idx]->addValue(SHUNT_RMPCT, atof(split_line[7].c_str()));
01675
01676
01677
01678
01679
01680 p_busData[o_idx]->addValue(SHUNT_RMIDNT, split_line[8].c_str());
01681
01682
01683
01684
01685
01686 p_busData[o_idx]->addValue(SHUNT_BINIT, atof(split_line[9].c_str()));
01687
01688 if (nval > 10)
01689 p_busData[o_idx]->addValue(SHUNT_N1, atoi(split_line[10].c_str()));
01690
01691
01692
01693
01694
01695 if (nval > 12)
01696 p_busData[o_idx]->addValue(SHUNT_N2, atoi(split_line[12].c_str()));
01697
01698
01699
01700
01701
01702 if (nval > 14)
01703 p_busData[o_idx]->addValue(SHUNT_N3, atoi(split_line[14].c_str()));
01704
01705
01706
01707
01708
01709 if (nval > 16)
01710 p_busData[o_idx]->addValue(SHUNT_N4, atoi(split_line[16].c_str()));
01711
01712
01713
01714
01715
01716 if (nval > 18)
01717 p_busData[o_idx]->addValue(SHUNT_N5, atoi(split_line[18].c_str()));
01718
01719
01720
01721
01722
01723 if (nval > 20)
01724 p_busData[o_idx]->addValue(SHUNT_N6, atoi(split_line[20].c_str()));
01725
01726
01727
01728
01729
01730 if (nval > 22)
01731 p_busData[o_idx]->addValue(SHUNT_N7, atoi(split_line[22].c_str()));
01732
01733
01734
01735
01736
01737 if (nval > 24)
01738 p_busData[o_idx]->addValue(SHUNT_N8, atoi(split_line[24].c_str()));
01739
01740
01741
01742
01743
01744 if (nval > 11)
01745 p_busData[o_idx]->addValue(SHUNT_B1, atof(split_line[11].c_str()));
01746
01747
01748
01749
01750
01751 if (nval > 13)
01752 p_busData[o_idx]->addValue(SHUNT_B2, atof(split_line[13].c_str()));
01753
01754
01755
01756
01757
01758 if (nval > 15)
01759 p_busData[o_idx]->addValue(SHUNT_B3, atof(split_line[15].c_str()));
01760
01761
01762
01763
01764
01765 if (nval > 17)
01766 p_busData[o_idx]->addValue(SHUNT_B4, atof(split_line[17].c_str()));
01767
01768
01769
01770
01771
01772 if (nval > 19)
01773 p_busData[o_idx]->addValue(SHUNT_B5, atof(split_line[19].c_str()));
01774
01775
01776
01777
01778
01779 if (nval > 21)
01780 p_busData[o_idx]->addValue(SHUNT_B6, atof(split_line[21].c_str()));
01781
01782
01783
01784
01785
01786 if (nval > 23)
01787 p_busData[o_idx]->addValue(SHUNT_B7, atof(split_line[23].c_str()));
01788
01789
01790
01791
01792
01793 if (nval > 25)
01794 p_busData[o_idx]->addValue(SHUNT_B8, atof(split_line[25].c_str()));
01795
01796 p_istream.nextLine(line);
01797 }
01798 }
01799
01800 void find_imped_corr()
01801 {
01802 std::string line;
01803
01804 p_istream.nextLine(line);
01805
01806 while(test_end(line)) {
01807 std::vector<std::string> split_line;
01808 this->cleanComment(line);
01809 boost::split(split_line, line, boost::algorithm::is_any_of(","),
01810 boost::token_compress_off);
01811 int nval = split_line.size();
01812 int entries = nval-1;
01813 entries = entries - entries%2;
01814 entries = entries/2;
01815 if (entries == 0) continue;
01816 boost::shared_ptr<gridpack::component::DataCollection>
01817 data(new gridpack::component::DataCollection);
01818
01819
01820
01821
01822
01823 int tableid = atoi(split_line[0].c_str());
01824 data->addValue(XFMR_CORR_TABLE_NUMBER, tableid);
01825
01826 int i;
01827 char buf[32];
01828 for (i=0; i<entries; i++) {
01829
01830
01831
01832
01833 sprintf(buf,"XFMR_CORR_TABLE_T%d",i+1);
01834 data->addValue(buf, atof(split_line[1+2*i].c_str()));
01835
01836
01837
01838
01839
01840 sprintf(buf,"XFMR_CORR_TABLE_F%d",i+1);
01841 data->addValue(buf, atof(split_line[2+2*i].c_str()));
01842 }
01843
01844 p_imp_corr_table.insert(std::pair<int,
01845 boost::shared_ptr<gridpack::component::DataCollection> >(tableid,data));
01846 p_istream.nextLine(line);
01847 }
01848 }
01849
01850 void find_multi_term()
01851 {
01852 std::string line;
01853
01854 p_istream.nextLine(line);
01855
01856 while(test_end(line)) {
01857
01858 p_istream.nextLine(line);
01859 }
01860 }
01861
01862 void find_multi_section()
01863 {
01864 std::string line;
01865
01866 p_istream.nextLine(line);
01867
01868 while(test_end(line)) {
01869 std::vector<std::string> split_line;
01870 this->cleanComment(line);
01871 boost::split(split_line, line, boost::algorithm::is_any_of(","),
01872 boost::token_compress_off);
01873 int o_idx1, o_idx2;
01874 o_idx1 = getBusIndex(split_line[0]);
01875 o_idx2 = getBusIndex(split_line[1]);
01876
01877
01878 int l_idx = 0;
01879 std::pair<int,int> branch_pair = std::pair<int,int>(o_idx1, o_idx2);
01880 #ifdef OLD_MAP
01881 std::map<std::pair<int, int>, int>::iterator it;
01882 #else
01883 boost::unordered_map<std::pair<int, int>, int>::iterator it;
01884 #endif
01885 it = p_branchMap.find(branch_pair);
01886 int nelems;
01887 bool found = false;
01888 if (it != p_branchMap.end()) {
01889 l_idx = it->second;
01890 found = true;
01891 } else {
01892
01893 std::pair<int, int> new_branch_pair;
01894 new_branch_pair = std::pair<int,int>(o_idx2, o_idx1);
01895 it = p_branchMap.find(new_branch_pair);
01896 if (it != p_branchMap.end()) {
01897 l_idx = it->second;
01898 found = true;
01899 }
01900 }
01901 nelems = split_line.size() - 3;
01902
01903 if (!found || nelems <= 0) continue;
01904
01905
01906 gridpack::utility::StringUtils util;
01907 std::string tag = util.clean2Char(split_line[2]);
01908 if (tag.length() != 2 || tag[0] != '&') {
01909 tag = "&1";
01910 }
01911
01912
01913
01914
01915
01916 p_branchData[l_idx]->addValue(MULTI_SEC_LINE_ID, tag.c_str());
01917
01918
01919
01920
01921
01922 p_branchData[l_idx]->addValue(MULTI_SEC_LINE_MET, atoi(split_line[3].c_str()));
01923
01924
01925 int i;
01926 char buf[32];
01927 for (i=0; i<9; i++) {
01928 sprintf(buf,"MULTI_SEC_LINE_DUM%d",i+1);
01929 p_branchData[l_idx]->addValue(buf,atoi(split_line[i+4].c_str()));
01930 }
01931
01932 p_istream.nextLine(line);
01933 }
01934 }
01935
01936
01937
01938
01939
01940 void find_zone()
01941 {
01942 std::string line;
01943
01944 p_istream.nextLine(line);
01945 while(test_end(line)) {
01946
01947 p_istream.nextLine(line);
01948 }
01949 }
01950
01951 void find_interarea()
01952 {
01953 std::string line;
01954
01955 p_istream.nextLine(line);
01956
01957 while(test_end(line)) {
01958 #if 0
01959 std::vector<std::string> split_line;
01960 boost::split(split_line, line, boost::algorithm::is_any_of(","), boost::token_compress_off);
01961 std::vector<gridpack::component::DataCollection> inter_area_instance;
01962 gridpack::component::DataCollection data;
01963
01964
01965
01966
01967
01968 data.addValue(INTERAREA_TRANSFER_FROM, atoi(split_line[0].c_str()));
01969 inter_area_instance.push_back(data);
01970
01971
01972
01973
01974
01975 data.addValue(INTERAREA_TRANSFER_TO, atoi(split_line[0].c_str()));
01976 inter_area_instance.push_back(data);
01977
01978
01979
01980
01981
01982 data.addValue(INTERAREA_TRANSFER_TRID, split_line[0].c_str()[0]);
01983 inter_area_instance.push_back(data);
01984
01985
01986
01987
01988
01989 data.addValue(INTERAREA_TRANSFER_PTRAN, atof(split_line[0].c_str()));
01990 inter_area_instance.push_back(data);
01991
01992 inter_area.push_back(inter_area_instance);
01993 #endif
01994 p_istream.nextLine(line);
01995 }
01996 }
01997
01998
01999
02000
02001
02002
02003
02004
02005 void find_owner()
02006 {
02007 std::string line;
02008 p_istream.nextLine(line);
02009
02010 while(test_end(line)) {
02011 #if 0
02012 std::vector<std::string> split_line;
02013 boost::split(split_line, line, boost::algorithm::is_any_of(","), boost::token_compress_off);
02014 std::vector<gridpack::component::DataCollection> owner_instance;
02015 gridpack::component::DataCollection data;
02016
02017 data.addValue(OWNER_NUMBER, atoi(split_line[0].c_str()));
02018 owner_instance.push_back(data);
02019
02020 data.addValue(OWNER_NAME, split_line[1].c_str());
02021 owner_instance.push_back(data);
02022
02023 owner.push_back(owner_instance);
02024 #endif
02025 p_istream.nextLine(line);
02026 }
02027 }
02028
02029 void find_facts()
02030 {
02031 std::string line;
02032 p_istream.nextLine(line);
02033
02034 while(test_end(line)) {
02035 p_istream.nextLine(line);
02036 }
02037 }
02038
02039
02040 void brdcst_data(void)
02041 {
02042 int t_brdcst = p_timer->createCategory("Parser:brdcst_data");
02043 int t_serial = p_timer->createCategory("Parser:data packing and unpacking");
02044 MPI_Comm comm = static_cast<MPI_Comm>(p_network->communicator());
02045 int me(p_network->communicator().rank());
02046 int nprocs(p_network->communicator().size());
02047 if (nprocs == 1) return;
02048 p_timer->start(t_brdcst);
02049
02050
02051
02052 int sbus, sbranch;
02053 if (me == 0) {
02054 sbus = p_busData.size();
02055 sbranch = p_branchData.size();
02056 } else {
02057 sbus = 0;
02058 sbranch = 0;
02059 }
02060 int ierr, nbus, nbranch;
02061 ierr = MPI_Allreduce(&sbus, &nbus, 1, MPI_INT, MPI_SUM, comm);
02062 ierr = MPI_Allreduce(&sbranch, &nbranch, 1, MPI_INT, MPI_SUM, comm);
02063 double rprocs = static_cast<double>(nprocs);
02064 double rme = static_cast<double>(me);
02065 int n, i;
02066 std::vector<gridpack::component::DataCollection>recvV;
02067
02068 if (me == 0) {
02069 for (n=0; n<nprocs; n++) {
02070 double rn = static_cast<double>(n);
02071 int istart = static_cast<int>(static_cast<double>(nbus)*rn/rprocs);
02072 int iend = static_cast<int>(static_cast<double>(nbus)*(rn+1.0)/rprocs);
02073 if (n != 0) {
02074 p_timer->start(t_serial);
02075 std::vector<gridpack::component::DataCollection> sendV;
02076 for (i=istart; i<iend; i++) {
02077 sendV.push_back(*(p_busData[i]));
02078 }
02079 p_timer->stop(t_serial);
02080 static_cast<boost::mpi::communicator>(p_network->communicator()).send(n,n,sendV);
02081 } else {
02082 p_timer->start(t_serial);
02083 for (i=istart; i<iend; i++) {
02084 recvV.push_back(*(p_busData[i]));
02085 }
02086 p_timer->stop(t_serial);
02087 }
02088 }
02089 } else {
02090 int istart = static_cast<int>(static_cast<double>(nbus)*rme/rprocs);
02091 int iend = static_cast<int>(static_cast<double>(nbus)*(rme+1.0)/rprocs)-1;
02092 static_cast<boost::mpi::communicator>(p_network->communicator()).recv(0,me,recvV);
02093 }
02094 int nsize = recvV.size();
02095 p_busData.clear();
02096 p_timer->start(t_serial);
02097 for (i=0; i<nsize; i++) {
02098 boost::shared_ptr<gridpack::component::DataCollection> data(new
02099 gridpack::component::DataCollection);
02100 *data = recvV[i];
02101 p_busData.push_back(data);
02102 }
02103 p_timer->stop(t_serial);
02104 recvV.clear();
02105
02106 if (me == 0) {
02107 for (n=0; n<nprocs; n++) {
02108 double rn = static_cast<double>(n);
02109 int istart = static_cast<int>(static_cast<double>(nbranch)*rn/rprocs);
02110 int iend = static_cast<int>(static_cast<double>(nbranch)*(rn+1.0)/rprocs);
02111 if (n != 0) {
02112 p_timer->start(t_serial);
02113 std::vector<gridpack::component::DataCollection> sendV;
02114 for (i=istart; i<iend; i++) {
02115 sendV.push_back(*(p_branchData[i]));
02116 }
02117 p_timer->stop(t_serial);
02118 static_cast<boost::mpi::communicator>(p_network->communicator()).send(n,n,sendV);
02119 } else {
02120 p_timer->start(t_serial);
02121 for (i=istart; i<iend; i++) {
02122 recvV.push_back(*(p_branchData[i]));
02123 }
02124 p_timer->stop(t_serial);
02125 }
02126 }
02127 } else {
02128 int istart = static_cast<int>(static_cast<double>(nbranch)*rme/rprocs);
02129 int iend = static_cast<int>(static_cast<double>(nbranch)*(rme+1.0)/rprocs)-1;
02130 static_cast<boost::mpi::communicator>(p_network->communicator()).recv(0,me,recvV);
02131 }
02132 nsize = recvV.size();
02133 p_branchData.clear();
02134 p_timer->start(t_serial);
02135 for (i=0; i<nsize; i++) {
02136 boost::shared_ptr<gridpack::component::DataCollection> data(new
02137 gridpack::component::DataCollection);
02138 *data = recvV[i];
02139 p_branchData.push_back(data);
02140 }
02141 p_timer->stop(t_serial);
02142 #if 0
02143
02144 printf("p[%d] BUS data size: %d\n",me,p_busData.size());
02145 for (i=0; i<p_busData.size(); i++) {
02146 printf("p[%d] Dumping bus: %d\n",me,i);
02147 p_busData[i]->dump();
02148 }
02149 printf("p[%d] BRANCH data size: %d\n",me,p_branchData.size());
02150 for (i=0; i<p_branchData.size(); i++) {
02151 printf("p[%d] Dumping branch: %d\n",me,i);
02152 p_branchData[i]->dump();
02153 }
02154 #endif
02155 p_timer->stop(t_brdcst);
02156 }
02157
02158 private:
02159
02160
02161
02162
02163 bool test_end(std::string &str) const
02164 {
02165 #if 1
02166 if (str[0] == TERM_CHAR) {
02167 return false;
02168 }
02169 int len = str.length();
02170 int i=0;
02171 while (i<len && str[i] == ' ') {
02172 i++;
02173 }
02174 if (i<len && str[i] != TERM_CHAR) {
02175 return true;
02176 } else if (i == len) {
02177 return true;
02178 } else if (str[i] == TERM_CHAR) {
02179 i++;
02180 if (i>=len || str[i] == ' ' || str[i] == '\\') {
02181 return false;
02182 } else {
02183 return true;
02184 }
02185 } else {
02186 return true;
02187 }
02188 #else
02189 if (str[0] == '0') {
02190 return false;
02191 } else {
02192 return true;
02193 }
02194 #endif
02195 }
02196
02197
02198
02199
02200
02201 bool check_comment(std::string &str) const
02202 {
02203 int ntok = str.find_first_not_of(' ',0);
02204 if (ntok != std::string::npos && ntok+1 != std::string::npos &&
02205 str[ntok] == '/' && str[ntok+1] == '/') {
02206 return true;
02207 } else {
02208 return false;
02209 }
02210 }
02211
02212
02213
02214
02215 void remove_blanks(std::string &str)
02216 {
02217 int ntok1 = str.find_first_not_of(' ',0);
02218 int ntok2 = str.length()-1;
02219 while (str[ntok2] == ' ') {ntok2--;}
02220 str = str.substr(ntok1, ntok2-ntok1+1);
02221 }
02222
02223
02224
02225
02226
02227 bool check_string(std::string &str)
02228 {
02229 int ntok1 = str.find_first_not_of(' ',0);
02230 if (ntok1 != std::string::npos && str[ntok1] == '\'') {
02231 ntok1++;
02232 int ntok2 = str.find_first_of('\'',ntok1);
02233 if (ntok2-ntok1 > 1 && ntok2 != std::string::npos) {
02234 ntok2--;
02235 str = str.substr(ntok1, ntok2-ntok1+1);
02236 } else if (ntok2 == std::string::npos && str.length()-1 - ntok1 > 1) {
02237 ntok2 = str.length()-1;
02238 str = str.substr(ntok1, ntok2-ntok1+1);
02239 } else {
02240 str.clear();
02241 }
02242
02243 if (str.length() > 0) remove_blanks(str);
02244 return true;
02245 } else {
02246
02247
02248 remove_blanks(str);
02249 return false;
02250 }
02251 }
02252
02253
02254
02255
02256
02257
02258
02259 void parseBusName(std::string &string, std::string &name, double &voltage)
02260 {
02261
02262 name = string;
02263 voltage = 0.0;
02264 int len = string.length();
02265 if (len > 12) {
02266
02267 int ntok1 = string.find(" ",0);
02268 if (ntok1 != std::string::npos) {
02269 name = string.substr(0,ntok1);
02270 int ntok2 = string.find_first_not_of(' ',ntok1);
02271 if (ntok2 != std::string::npos) {
02272 voltage = atof(string.substr(ntok2,len-ntok2).c_str());
02273 }
02274 }
02275 }
02276 return;
02277 }
02278
02279
02280
02281
02282
02283 void storeBus(std::string &string, int idx)
02284 {
02285 check_string(string);
02286 std::pair<std::string,int> name_pair;
02287 name_pair = std::pair<std::string,int>(string,abs(idx));
02288 p_nameMap.insert(name_pair);
02289 }
02290
02291
02292
02293
02294
02295
02296 int getBusIndex(std::string str)
02297 {
02298 if (check_string(str)) {
02299 std::string name;
02300 double voltage;
02301 parseBusName(str,name,voltage);
02302 #ifdef OLD_MAP
02303 std::map<std::string,int>::iterator it;
02304 #else
02305 boost::unordered_map<std::string, int>::iterator it;
02306 #endif
02307 it = p_nameMap.find(name);
02308 if (it != p_nameMap.end()) {
02309 return it->second;
02310 } else {
02311 return -1;
02312 }
02313 } else {
02314 return abs(atoi(str.c_str()));
02315 }
02316 }
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349 boost::shared_ptr<_network> p_network;
02350
02351
02352 std::vector<boost::shared_ptr<gridpack::component::DataCollection> > p_busData;
02353
02354 std::vector<boost::shared_ptr<gridpack::component::DataCollection> > p_branchData;
02355
02356 std::map<int,boost::shared_ptr<gridpack::component::DataCollection> >
02357 p_imp_corr_table;
02358
02359 #ifdef OLD_MAP
02360 std::map<int,int> p_busMap;
02361 std::map<std::string,int> p_nameMap;
02362 #else
02363 boost::unordered_map<int, int> p_busMap;
02364 boost::unordered_map<std::string, int> p_nameMap;
02365 #endif
02366
02367 #ifdef OLD_MAP
02368 std::map<std::pair<int, int>, int> p_branchMap;
02369 #else
02370 boost::unordered_map<std::pair<int, int>, int> p_branchMap;
02371 #endif
02372
02373
02374 gridpack::stream::InputStream p_istream;
02375
02376
02377 int p_case_id;
02378 int p_maxBusIndex;
02379 double p_case_sbase;
02380 gridpack::utility::CoarseTimer *p_timer;
02381
02382
02383
02384
02385 boost::shared_ptr<gridpack::component::DataCollection> p_network_data;
02386 };
02387
02388 }
02389 }
02390 #endif